package com.ptszyxx.popose.module.main.home.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ptszyxx.popose.common.enums.RankEnum;
import com.ptszyxx.popose.common.enums.RankItemEnum;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseListResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessListResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.home.HomeRankEntity;
import com.ysg.utils.YToastUtil;

import java.util.HashMap;
import java.util.Map;

public class HomeRankDataVM extends BaseViewModel<CommonRepository> {
    public RankEnum rankEnum;
    public RankItemEnum rankItemEnum;

    public HomeRankDataVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onRefreshEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onCloseCommand = new BindingCommand(()-> YActivityUtil.getInstance().close(this));
    public BindingCommand onHelpCommand = new BindingCommand(()-> YToastUtil.showShort("排行规则"));


    //=========================================接口：start===========================================

    public void requestRank(){
        Map<String, String> map = new HashMap<>();
        if (rankEnum != null) map.put("type", rankEnum.getType());
        if (rankItemEnum != null) map.put("secondType", rankItemEnum.getType());

        HttpUtils.getInstance()
                .list(model.rankList(map), this,
                        new OnSuccessListResult<HomeRankEntity>() {
                            @Override
                            public void onSuccessResult(BaseListResponse<HomeRankEntity> response) {
                                uc.onRefreshEvent.setValue(response.getData());
                            }
                        });
    }
}
